import 'package:flutter/material.dart';

class GridViewBuidCase extends StatelessWidget {
  const GridViewBuidCase({Key? key}) : super(key: key);

  List<Widget> getList() {
    return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((int i) {
      return Container(
        alignment: Alignment.center,
        margin: const EdgeInsets.all(10),
        decoration: const BoxDecoration(
          color: Colors.blue,
          borderRadius: BorderRadius.all(Radius.circular(10)),
        ),
        width: double.infinity,
        height: 100,
        child: Text("我是第$i个"),
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2, // 3列
            mainAxisSpacing: 10, // 主轴间隔
            crossAxisSpacing: 10, // 纵轴间隔
            childAspectRatio: 1 // 宽高比
            ),
        itemBuilder: (context, index) {
          return Container(
            alignment: Alignment.center,
            margin: const EdgeInsets.all(10),
            decoration: const BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.all(Radius.circular(10)),
            ),
            width: double.infinity,
            height: 100,
            child: Text("我是第$index个"),
          );
        });
  }
}
